import time

from ddt import ddt, data, unpack
from unittest import TestCase
from selenium import webdriver
from RegisterData import RegisterData
from RegisterOperation import RegisterOperation


@ddt
class TestSign(TestCase):
    @data(*RegisterData.register_data)
    @unpack
    def testSign1(self, casename, username, password, repwd, usertype, sex, hobby, email, introduction, expect):
        #  开始测试
        driver = webdriver.Chrome()
        # 打开浏览器页面并最大化
        driver.get("file:///D:/WeChat%20Files/wxid_ho1z2hz3uaqm22/FileStorage/File/2023-07/Login%E6%BC%94%E7%A4%BA%E9%A1%B5%E9%9D%A2/register.html")
        driver.maximize_window()
        # 执行注册
        register = RegisterOperation()
        register.register(driver, username, str(int(password)), str(int(repwd)), usertype, sex, hobby, email, introduction)
        driver.execute_script("window.open('D:/WeChat Files/wxid_ho1z2hz3uaqm22/FileStorage/File/2023-07/Login演示页面/login.html','new window')")
        time.sleep(1)
        # 获取标签页句柄
        data = driver.window_handles
        driver.switch_to.window(data[1])
        # 获取注册成功实际结果
        result = register.register_result(driver, username, str(int(password)))
        if result != expect:
            driver.save_screenshot(casename + '.jpg')
        else:
            print('通过')

        driver.quit()

        self.assertEqual(result, expect)
